-module (web_code).
-include_lib ("nitrogen/include/wf.inc").
-compile(export_all).

make() ->
    hglobals:vput(helper:id_me(), caller, ?MODULE),
    state:make( [ 
		  {login_block, false, true, false},
		  {open_code_block, false, false, true},
		  {handle_code_block, false, true, false},
		  {cbrowser_block, false, true, false}
						%This page will manually use the functions from the modules for the body
						% {interpreter_block, false, false, true}, 
						% {toplevel_block, false, false, true}
		 ] ).

main() -> 
    #template { file="./wwwroot/template.html"}.

title() ->
    "Hertz :: Créez !".

wire() ->
    wf:wire(toplevel_panel, #hide{}),
    wf:wire(ip_btn, #event{target=toplevel_panel, actions=#hide{}}),
    wf:wire(ip_btn, #event{target=interpreter_panel, actions=#show{}}),
    wf:wire(tp_btn, #event{target=toplevel_panel, actions=#show{}}),
    wf:wire(tp_btn, #event{target=interpreter_panel, actions=#hide{}}).

manual() ->
    %% case hglobals:vget(helper:id_me(), connected) of
    %% 	true -> ok;
    %% 	_ -> wf:flash("N'oubliez pas de vous connecter / inscrire pour sauver votre code!")
    %% end,
						%TODO : Do something useful w/ the code above

    Interpreter = #panel{id=interpreter_panel, body=interpreter_block:assemble_body([]), style="width:100%;"},
    Toplevel = #panel{id=toplevel_panel, body=toplevel_block:assemble_body([]), style="width:100%;"},
    [
     #p{},
     #rounded_panel{ color=gray, body=[
				       #button{id=ip_btn, text = "Editez votre code", style="width: 50%;"},
				       #button{id=tp_btn, text = "Ligne de commande", style="width: 50%;"}
				      ], style="width: 100%;"},
     #p{},
     Interpreter,
     Toplevel
    ].

body() ->
    wire(),

    wf:render(hglobals:vget(helper:id_me(), body) ++ manual()).

event(_) -> ok.

exec(Fun, Arg) -> 
    Fun(Arg).

						%Yeah, this sucks.
inplace_textbox_event(_Tag, Value) ->
    hglobals:vput(helper:id_me(), hcb_code_name, Value),
    Value.
